package com.liuchuanzheng.lcz_changeconfig

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.liuchuanzheng.lcz_changeconfig.config.ConfigManager
import com.liuchuanzheng.lcz_changeconfig.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {
    lateinit var mViewBinding :ActivityMainBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mViewBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(mViewBinding.root)

        val currentConfig = ConfigManager.getCurrentConfig()
        val stringBuilder = StringBuilder()
        stringBuilder.append("当前使用的环境是:\n")
        stringBuilder.append("名称: ${currentConfig.mName}\n")
        stringBuilder.append("tips: ${currentConfig.tips}\n")
        stringBuilder.append("url: ${currentConfig.url}")
        mViewBinding.tvConfig.setText(stringBuilder.toString())
        if (ConfigManager.getCurrenFlor().equals(ConfigManager.FLAVOR_AUTO)) {
            mViewBinding.tvTips.setText("当前是auto模式,可以自由切换环境")
            mViewBinding.btnChange.visibility = View.VISIBLE
            mViewBinding.btnChange.setOnClickListener {
                startActivity(Intent(this, ChangeConfigActivity::class.java))
            }
        }else{
            mViewBinding.tvTips.setText("当前是online模式,不能切换环境")
            mViewBinding.btnChange.visibility = View.GONE
        }
    }
}